using System;
using System.Collections.Generic;
using System.Linq;
using Headsight.BPMN2WF.BPMN.Schemas;

namespace Headsight.BPMN2WF.BPMN.Model
{
    public class BPMNElementVisualFactory
    {
        public IDictionary<String, BPMNElementVisual> Create(tDefinitions tDefinitions)
        {
            // ^^ sufficient for now. Probably there must come tProcess into the game someday in future....
            var result = new Dictionary<String, BPMNElementVisual>();

            if (tDefinitions.BPMNDiagram == null || tDefinitions.BPMNDiagram.Length == 0 )
            {
                return result;
            }

            var bpmnDiagram = tDefinitions.BPMNDiagram[0];

            if (bpmnDiagram.BPMNPlane == null || bpmnDiagram.BPMNPlane.DiagramElements == null)
            {
                return result;
            }

            var diagElems = bpmnDiagram.BPMNPlane.DiagramElements;

            foreach (var each in diagElems.OfType<BPMNShape>())
            {
                result[each.bpmnElement.Name] = new BPMNElementVisual(each);
            }

            return result;
        }
    }
}